/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aptech.eproject.controler;

import aptech.eproject.DBConnection;
import aptech.eproject.entity.Bills;
import aptech.eproject.entity.Coupons;
import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 *
 * @author Ntienbo
 */
public class CouponsControler {

    DBConnection db;
    Connection conn;

    public CouponsControler() {
        db = new DBConnection();
    }

    public boolean insertCoupons(Coupons c) {
        try {
            conn = db.getConnect();
            PreparedStatement statement = conn.prepareStatement("INSERT INTO Coupons VALUES"
                    + " (?,?,?)", ResultSet.CONCUR_UPDATABLE, ResultSet.TYPE_SCROLL_SENSITIVE);
            statement.setInt(1, c.getCouponID());
            statement.setFloat(2, c.getCriteria());
            statement.setFloat(3, c.getCPercent());
            statement.executeUpdate();
            return true;
        } catch (Exception ex) {
            return false;
        }
    }

    public boolean deleteCoupons(Coupons c) {
        try {
            PreparedStatement statement = conn.prepareStatement("DELETE Coupons WHERE CouponID=?", ResultSet.CONCUR_UPDATABLE, ResultSet.TYPE_SCROLL_SENSITIVE);
            statement.setInt(1, c.getCouponID());
            statement.executeUpdate();
            return true;
        } catch (SQLException ex) {
            return false;
        }

    }

    public boolean updateCoupons(Coupons c) {
        try {
            PreparedStatement statement = conn.prepareStatement("UPDATE Coupons SET "
                    + "(Criteria=?,CPercent=?)  WHERE CouponID=?");
            statement.setFloat(1, c.getCriteria());
            statement.setFloat(2, c.getCPercent());
            statement.setInt(3, c.getCouponID());
            return true;
        } catch (SQLException ex) {
            return false;
        }

    }
}
